package com.wgy.blog.common.handler;


import com.wgy.blog.common.Result;
import com.wgy.blog.common.exception.MyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler({Exception.class})
    @ResponseBody
    public String handException(Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }

    @ExceptionHandler({MyException.class})
    @ResponseBody
    public Result<String> handMyException(Exception e) {
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler({ NullPointerException.class})
    @ResponseBody
    public Result<String> nullPointerException(Exception e) {
        e.printStackTrace();
        return Result.fail("空指针异常");
    }



    
//    @ExceptionHandler({ArithmeticException.class})
//    @ResponseBody
//    public String handArithmeticException(Exception e) {
//        e.printStackTrace();
//        return "0000000000000";
//    }
}